<template>
  <div class="repairList">
    <div class="tabBox">
      <el-tabs v-model="activeName" @tab-click="handleClick">
        <el-tab-pane label="全部" name="0"></el-tab-pane>
        <el-tab-pane label="未完成" name="1"></el-tab-pane>
        <el-tab-pane label="已处理" name="2"></el-tab-pane>
      </el-tabs>
    </div>
    <div class="searchBox">
      <el-form ref="form" :model="formData" label-width="80px" size="mini">
        <el-row :gutter="20">
          <el-col :span="8"
            v-if="activeName=='0'"><div>
              <el-form-item label="处理状态">
                <el-select
                  v-model="formData.status"
                  placeholder="请选择处理状态"
                >
                  <el-option v-for="(item,index) in statusList" :key="index" :label="item.dictName" :value="item.dictValue"></el-option>
                </el-select>
              </el-form-item></div
          ></el-col>
          <el-col :span="8"
            ><div>
              <el-form-item label="提交日期">
                <el-date-picker
                  v-model="formData.dateArr"
                  type="daterange"
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  format="yyyy-MM-dd"
                  value-format="yyyy-MM-dd"
                >
                </el-date-picker>
              </el-form-item></div
          ></el-col>
          <el-col :span="8"
            ><div>
              <el-button size="mini" type="primary" @click="getRepairPage">查询</el-button>
              <el-button size="mini" @click="reset">重置</el-button>
              <el-button size="mini" @click="exportFile">导出</el-button>
            </div></el-col
          >
        </el-row>
      </el-form>
    </div>
    <div class="tableBox">
      <div class="addBtnBox">
        <el-button
          size="small"
          type="primary"
          icon="el-icon-circle-plus-outline"
        @click="goAdd()"
        >新建</el-button
        >
      </div>
      <div class="repairTable">
        <el-table
          :data="tableData"
          style="width: 100%"
          stripe
          border
          :header-cell-style="{ background: '#409EFF', color: '#FFFFFF' }"
        >
          <el-table-column label="编号" show-overflow-tooltip width="80px">
            <template slot-scope="scope">
              <span>{{ scope.row.No }}</span>
            </template>
          </el-table-column>
          <el-table-column label="关联房产编号" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.projectId }}</span>
            </template>
          </el-table-column>
          <el-table-column
              label="区域"
              show-overflow-tooltip
              :formatter="$_formatAreaStatus"
              prop="serviceRange"
          >
          </el-table-column>
          <el-table-column label="故障设备" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.relateDeviceTypeName }}</span>
            </template>
          </el-table-column>
          <el-table-column label="服务费(元)" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.serviceFee }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="处理状态"
            show-overflow-tooltip
            :formatter="$_formatStatus"
            prop="serviceStatus"
          >
          </el-table-column>

          <el-table-column label="更新时间" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.updateDate }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" width="80px">
            <template slot-scope="scope">
              <el-button type="text" size="mini" @click="doDetail(scope.row)"
                >查看</el-button
              >
            </template>
          </el-table-column>
        </el-table>
      </div>
      <div class="fenyeBox">
        <el-pagination
          :hide-on-single-page="false"
          @current-change="handleCurrentChange"
          :current-page.sync="currentPage"
          :page-size="perPage"
          layout="prev, pager, next, total,jumper"
          :total="totalNumber"
        ></el-pagination>
      </div>
    </div>
  </div>
</template>
<script>
import api from "../../../api/app";
export default {
  data() {
    return {
      activeName: "0",
      //分页数据
      nowPage: 1,
      perPage: 10,
      currentPage: 1,
      PageCount: 0,
      totalNumber: 0,
      formData: {
        status: "",
        dateArr: ['',''],
      },
      tableData: [

      ],
      areaList:[{
        dictValue: 1,
        dictName: "房内区域",
      },{
        dictValue: 2,
        dictName: "公共区域",
      }],
      //工单状态(1.待创建 2.已创建 3.已接单 4.已完成)
      statusList: [
        {
          dictValue: '1',
          dictName: "待创建",
        },
        {
          dictValue: '2',
          dictName: "已创建",
        },
        {
          dictValue: '3',
          dictName: "已接单",
        },
        {
          dictValue: '4',
          dictName: "已完成",
        },
      ],
    };
  },
  mounted() {
    this.getRepairPage()
  },
  methods: {
    doDetail(obj){
      this.$router.push({path:'/reportDetail',query:{id:obj.id}})
    },
    exportFile(){
      let data={
        current:this.nowPage,
        size:this.perPage,
        startDate:this.formData.dateArr[0],
        endDate:this.formData.dateArr[1],
        searchType:this.activeName,
        serviceStatus:this.formData.status
      }
      api.ExportFile('/repair/business/repair/outputService',data)
    },
    reset(){
      this.formData={
        status: "",
            dateArr: ['',''],
      }
    },
    getRepairPage() {
      if(!this.formData.dateArr){
        this.formData.dateArr=['','']
      }
      let data={
        current:this.nowPage,
        size:this.perPage,
        startDate:this.formData.dateArr[0],
        endDate:this.formData.dateArr[1],
        searchType:this.activeName,
        serviceStatus:this.formData.status
      }
      api
          .getRepairPage(data)
          .then((res) => {
            console.log(res);
            this.tableData=[]
            let tempList = res.data.data.records;
            for (let i = 0; i < tempList.length; i++) {
              let tempObj = {};
              tempObj = tempList[i];
              tempObj.No=(res.data.current-1)*this.perPage+i+1
              this.tableData.push(tempObj);
            }
            this.totalNumber=res.data.total
            this.nowPage=res.data.current
          })
          .catch((err) => {console.log(err)});
    },
    handleClick(tab, event) {
      console.log(tab, event);
      if(this.activeName!='0'){
        this.formData.status=''
      }
      this.getRepairPage()
    },
    $_formatStatus(row, column, cellValue) {
      let _types = this.statusList || [];
      let _obj =
        _types.find((value, index) => {
          console.log(index)
          return value.dictValue === cellValue;
        }) || {};
      return _obj.dictName || "";
    },
    $_formatAreaStatus(row, column, cellValue) {
      let _types = this.areaList || [];
      let _obj =
          _types.find((value, index) => {
            console.log(index)
            return value.dictValue === cellValue;
          }) || {};
      return _obj.dictName || "";
    },
    handleCurrentChange(val) {
      this.nowPage = val;
    },
    goAdd(){
      this.$router.push(
          {path:'/addRepairReport'}
      )
    }
  },
};
</script>
<style scoped>
.repairList {
  width: 1080px;
  margin: 0 auto;
  padding: 16px;
  min-height: 700px;
}
.searchBox >>> .el-range-editor--mini.el-input__inner {
  width: 100%;
}
.searchBox >>> .el-select {
  width: 100%;
}
.addBtnBox {
  text-align: left;
}
.repairTable {
  margin-top: 20px;
}
.fenyeBox {
  margin-top: 20px;
  text-align: right;
}
.tableBox >>> .el-table td,
.tableBox >>> .el-table th {
  text-align: center;
}
</style>
